<?php

use App\Http\Controllers\Api\BookController;
use App\Http\Controllers\Api\CommonController;
use App\Http\Controllers\Api\FollowController;
use App\Http\Controllers\Api\UserController;
use App\Http\Controllers\Api\WordController;
use Illuminate\Http\Request;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Route;
use Jiannei\Response\Laravel\Support\Facades\Response;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "api" middleware group. Make something great!
|
*/

Route::get('/test', function (Request $request) {
    return Response::fail('失败乃成功之母！');
    return Response::success(['test'=>'123']);
});
Route::post('login', [UserController::class, 'login']);

Route::group([
    'namespace' => 'App\\Http\\Controllers\\Api',
    //    'middleware' => ['api'],
], function (Router $router) {
    $router->get('books', [BookController::class, 'index']);
    $router->get('book/category', [BookController::class, 'category']);
    $router->get('book/{book}', [BookController::class, 'show']);

    $router->get('words', [WordController::class, 'index']);
    $router->get('word/{word}', [WordController::class, 'show']);

    $router->get('config', [CommonController::class, 'config']);

});

Route::group([
    'middleware' => ['auth']
], function (Router $router) {
    $router->get('auth/user', [UserController::class, 'me']);
    $router->post('auth/logout', [UserController::class, 'logout']);
    $router->post('auth/refresh', [UserController::class, 'refresh']);

    $router->get('user/follows/{type}', [FollowController::class, 'follows']);
    $router->post('follow/{type}/{id}', [FollowController::class, 'follow']);
    $router->post('unFollow/{type}/{id}', [FollowController::class, 'unFollow']);

    $router->post('user/update', [UserController::class, 'update']);

});
